package sjsu.cmpe235;

import java.util.Locale;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class SplashActivity extends Activity {
            
    private ViewPager mUserGuidePager;
    private RadioGroup mPageIndicatorRadioGroup;
    private Button mCloseButton;
    
    private UserGuidePagerAdapter mAdapter;
    
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);		
		
		mUserGuidePager = (ViewPager)findViewById(R.id.user_guide_pager);
		mPageIndicatorRadioGroup = (RadioGroup)findViewById(R.id.page_indicator_layout);
				
		mAdapter = new UserGuidePagerAdapter();
		mUserGuidePager.setAdapter(mAdapter);		
		
		mCloseButton = (Button) findViewById(R.id.buttonClose);
		mCloseButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
    }
    
    @Override
    protected void onStart() {
        super.onStart();
    }
    
    @Override
    protected void onStop() {
        super.onStop();
    }
        	
	
    private class UserGuidePagerAdapter extends PagerAdapter {
        private final int[] resIds = new int[] {
                R.drawable.user_guide_1,
                R.drawable.user_guide_2,
                R.drawable.user_guide_3
        };
        
        public UserGuidePagerAdapter() {
        }
        
        @Override
        public void startUpdate(View container) {
        }
        
        @Override
        public Parcelable saveState() {
            return null;
        }
        
        @Override
        public void restoreState(Parcelable state, ClassLoader loader) {
        }
        
        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == (View)object;
        }
        
        @Override
        public Object instantiateItem(View container, int position) {
            final ImageView view = new ImageView(SplashActivity.this);
            view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            view.setScaleType(ScaleType.FIT_START);
            view.setImageResource(resIds[position]);
            ((ViewPager)container).addView(view);
            return view;
        }
        
        @Override
        public int getCount() {
            return resIds.length;
        }
        
        @Override
        public void finishUpdate(View container) {
            final int position = ((ViewPager)container).getCurrentItem();
    		((RadioButton)mPageIndicatorRadioGroup.getChildAt(position)).setChecked(true);
        }
        
        @Override
        public void destroyItem(View container, int position, Object object) {
            ((ViewPager)container).removeView((View)object);
        }
    };
}
